<?php

$loader->requireOnce('ordo/Department.class.php');
/**
 * This class help to execute various actions for a menu item.
 *
 * The action depends on
 * <ol>
 * 	<li>The specific department</li>
 *  <li>The department type (IN_PATIENT or OUT_PATIENT)</li>
 *  <li>User roles</li>
 * </ol>
 *
 * @package core.includes
 * @author ptnguyen
 * @version $Id:$
 * @copyright 2009 LHV Company
 *
 */
class DynamicMenu {

	/**
	 * Reference to (@link Me.class.php) instance
	 * @var $me
	 */
	private $_me;

	function __construct($meObject) {
		if (!($meObject instanceof Me)) {
			throw new Exception('The parameter is not instance of Me');
		}
		$this->_me = $meObject;
	}

	/**
	 * Dynamic processing for queue menu item.
	 * @return array | false.
	 * 		If not found any mapping return false
	 * 		Else return array('controller' 	=> $expectedController
	 * 							'action'	=> $expectedAction)
	 */
	public function processQueueMenuItem() {
		$login2Dept = $this->_me->get_department_id();
		$userRole 	= 	$this->_me->get_role();

		$result = array('controller' 	=> '',
						'action'		=> '');
		$found = false;
		// check department that user logged in
		switch ($login2Dept) {
			case Department::EMERGENCY_DEPT_ID:
				$result['controller'] 	= 'EmergencyInPatient';
				$result['action']		= 'RenderDoctorQueues';
				$found = true;
			break;
			case Department::LABORATORY_DEPT_ID:
                $result['controller']   = 'LabQueue';
                $result['action']       = 'RenderQueue';
                $found = true;
                break;
			case Department::RADIOLOGY_DEPT_ID:
				$result['controller']   = 'RadQueue';
                $result['action']       = 'RenderQueue';
                $found = true;
                break;
		}

		if ($found) return $result;

		// check department type

		// check user role
		switch ($userRole) {
			case 'front_office':
				$result['controller'] 	= 'Queue';
				$result['action']		= 'ReceptionistQueue';
				$found = true;
				break;
			case 'doctor':
				$result['controller'] 	= 'Queue';
				$result['action']		= 'DoctorQueue';
				$found = true;
				break;
		}
		if ($found) return $result;

		return false;
	}

	/**
	 * Dynamic processing for AddPatient menu item.
	 * @return array | false.
	 * 		If not found any mapping return false
	 * 		Else return array('controller' 	=> $expectedController
	 * 							'action'	=> $expectedAction)
	 */
	public function processAddPatientMenuItem() {
		$login2Dept = $this->_me->get_department_id();

		$result = array('controller' 	=> '',
						'action'		=> '');
		$found = false;
		// check department that user logged in
		switch ($login2Dept) {
			case Department::EMERGENCY_DEPT_ID:
				$result['controller'] 	= 'EmerReception';
				$result['action']		= 'Register';
				$found = true;
				break;
			default:
				$result['controller'] 	= 'Patient';
				$result['action']		= 'AddOutPatient';
				$found = true;
				break;
		}

		if ($found) return $result;

		return false;
	}

	public function processCashierQueue() {
		$login2Dept = $this->_me->get_department_id();

		$result = array('controller' 	=> '',
						'action'		=> '');
		$found = false;
		// check department that user logged in
		switch ($login2Dept) {
			case Department::EMERGENCY_DEPT_ID:
				$result['controller'] 	= 'InCashier';
				$result['action']		= 'CashierQueue';
				$found = true;
				break;
			default:
				$result['controller'] 	= 'Queue';
				$result['action']		= 'CashierQueueForOutPatient';
				$found = true;
				break;
		}

		if ($found) return $result;

		return false;
	}
}
?>